﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Table_Dal;
using System.Data.SqlClient;
using System.Data;
namespace BLL
{
    public class DethiBLL
    {
        public DeThiTbl ThongTinDeTHi_Madethi(string Madethi)
        {
            DeThiDal dt = new DeThiDal();
            return dt.ThongTinDeThi(Madethi);
        }
        public List<DeThiTbl> LayDanhSachDeThi_MaMonHoc(string MaMonHoc,string mssv)
        {
            DeThiDal dt = new DeThiDal();
            if(mssv=="")
                return dt.LayDanhSachDeThi_MaMonHoc(MaMonHoc);
           return dt.LayDanhSachDeThi_MaMonHoc(MaMonHoc,mssv);
            
        }
        
        public bool ThemDethi(DeThiTbl Madethi,List<string> DSCauhoi)
        {
            try
            {
                BusinessLogicLayer bll = new BusinessLogicLayer();
                DeThiDal dt = new DeThiDal();
                string x = bll.RandomMa();
                while (dt.KiemTra_TrungKhoa(x))
                {
                    x = bll.RandomMa();
                }
                Madethi.MADETHI = x;
                
                dt.ThemDeThi(Madethi);
                foreach (string i in DSCauhoi)
                {
                    ChitietdethiDAL ctiet = new ChitietdethiDAL();
                    ChiTietDethiTbl chitiet = new ChiTietDethiTbl();
                    chitiet.MADETHI = x;
                    chitiet.MACAUHOI = i;
                    ctiet.ThemChiTietDethi(chitiet);
                }
            }
            catch
            {
                return false;
            }
            return true;
        }
        public bool XoaDethi(string Madethi)
        {
            DeThiDal dt = new DeThiDal();
            return dt.XoaDeThi(Madethi);
        }
        public List<DeThiTbl> LayTatDeThi()
        {
            DeThiDal dt = new DeThiDal();
            return dt.LayTatCaDeThi();
        }

        public void XoaDethiTheo_MaCauHoi(string p)
        {
            DeThiDal dt = new DeThiDal();
            dt.XoaDethiTheo_MaCauHoi(p);
        }
    }
}

